﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QuanLyKho.Server;

namespace QuanLyKho.Server
{
    public partial class PhieuNhapThuoc
    {
       
       public decimal TongTien
        {
            get
            {
                if (IdPhieuNhap != 0)
                {
                    using (QuanLyKhoEntities entities = new QuanLyKhoEntities(QuanLyKhoServerGlobal.ConnectionString))
                    {
                        List<PhieuNhapThuocChiTiet> list = entities.PhieuNhapThuocChiTiets.Where(u => u.IdPhieuNhap == IdPhieuNhap).ToList();
                        if (list.Count > 0)
                        {
                            return list.Sum(u => (u.GiaNhap*(100 - u.ChietKhau)/100) * u.SoLuong);
                        }
                        return 0;
                    }
                }
                return 0;
            }
        }
        public string NgayNhapDDMMYYYY {
            get
            {
                return NgayNhap.ToString("dd/MM/yyyy");
            }
        }

        public TienNo TienNo
        {
            get
            {
                if (IdPhieuNhap == 0)
                {
                    return null;
                }
                else
                {
                    TienNo tienNo = null;
                    using (QuanLyKhoEntities entities = new QuanLyKhoEntities(QuanLyKhoServerGlobal.ConnectionString))
                    {
                        tienNo = entities.TienNoes.FirstOrDefault(u=>u.IdPhieuNhap == IdPhieuNhap);
                    }
                    return tienNo;
                }
            }
        }

        public string TenNhaPhanPhoi
        {
            get
            {
                if (Dm_NhaPhanPhoi != null)
                    return Dm_NhaPhanPhoi.TenNhaPhanPhoi;
                return null;
            }
            set { ;}
        }
        
    }
}
